package juc.atom;

import java.util.concurrent.atomic.AtomicMarkableReference;

/**
 * @author liwuji
 * @date 2024/1/23
 * @desc
 **/
public class MarkableReference {
    
    private static AtomicMarkableReference<Integer> markableReference = new AtomicMarkableReference<>(100, false);
    public static void main(String[] args) {
        new Thread(()->{
            boolean marked = markableReference.isMarked();
            try {
                Thread.sleep(10000L);
            }catch (Exception e){
                e.printStackTrace();
            }
            markableReference.compareAndSet(2000, 1000, markableReference.isMarked(), !markableReference.isMarked());
            System.out.println(Thread.currentThread().getName()+" : "+markableReference.getReference());
        }).start();


        new Thread(()->{
             markableReference.compareAndSet(100, 2000, markableReference.isMarked(), !markableReference.isMarked());
            System.out.println(Thread.currentThread().getName()+" : "+markableReference.getReference());
        }).start();

        while (true){
            
        }
    }
}
